#!/bin/bash

# Alunos:   Eliezer de Souza da Silva  RA: 124065
#           Fernanda Brandao Silva     RA: 060727
#           Michel Silva Fornaciali    RA: 071884
# IA368R: Eduardo Valle - Trabalho 3, Programa 1 - Descricao de uma imagem
#  espera um numero variavel de parametros no argumentos com as consultas
number_of_args=$#

if [ $# -lt 1 ] ; then
   echo -e "Opps! I need atleast 1 command line args filename\n"
   echo -e "Syntax: $0: query1 query2 ... queryN\n"
   echo -e "Example:$0 qcam00000E_crop1x2.s050g10c00r40dn.ppm\n\t$0 qcel000076_crop1x1.s100g10c00r00dn.ppm qcam000058_crop1x2.s100g24c10r00dn.ppm" 
   exit 1
fi

for x in $*
do 
    echo "$x";
    if [ -e ~/datasets/VallePics/$x.descriptor ]
    	then
        	echo "found descriptor";
	else
		echo "creating descriptor";
		./descimagem.sh ~/datasets/VallePics/queries/$x > ~/datasets/VallePics/$x.descriptor;
    fi
    echo "consulta com kdtree"
    /usr/bin/time -f "%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax %Kavg)k" python consulta.py ~/datasets/VallePics/basedesc 10 < ~/datasets/VallePics/$x.descriptor > rank.$x.kd.txt 
    echo "consulta sem indexacao"
    /usr/bin/time -f "%Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax %Kavg)k" python consultaT3.py ~/datasets/VallePics/basedesc 10 < ~/datasets/VallePics/$x.descriptor > rank.$x.s.txt 
done
